package com.Listeners;

import com.Animations.AnimUtil;
import com.Dialogs.DialogManagerClass;
import com.Dialogs.DialogShare;
import com.Dialogs.DialogManagerClass.onCommentChange;
import com.Dialogs.DialogManagerClass.onTagChange;
import com.Dialogs.DialogShare.OnShareChanged;
import com.activities.ActivityAlbums;
import com.activities.ActivityUpload;


import com.shareup.R;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class MenuMineClickListener  implements OnItemClickListener{
	
	public static final int MINE_ALBUMS=0;
	public static final int MINE_TAGS=1;
	public static final int MINE_SEARCH=2;
	public static final int UPLOAD_COMMENT=3;
	public static final int UPLOAD_LOCATION=4;
	public static final int UPLOAD_TAGS=5;
	public static final int UPLOAD_ALBUM=6;
	public static final int UPLOAD_PRIVACY=7;
	
	
	private Activity context;
	private String privacy;
	
	private static View itemName;
	
	public MenuMineClickListener(Activity context) {
		super();
		this.context = context;
	}
	
	public static void setAlbumName(String albumName) {
		
		((TextView)itemName.findViewById(R.id.row_m_title)).setText(albumName);
			
	}
	
	public static void setPrivacy(String privacy) {
		((TextView)itemName.findViewById(R.id.row_m_title)).setText(privacy);
				
	}
		

	
	@Override
	public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
		
		itemName = v;
		
		if(!v.getTag().equals(MenuClickListener.ITEM_TYPE_HEADER))
		{
			int tag = (Integer) v.getTag();
			Intent intent;
			
			switch(tag)
			{
			case MINE_ALBUMS:
			    
				 intent = new Intent(context,ActivityAlbums.class);
				 context.startActivity(intent);
				 AnimUtil.getActivityTransition(context, true);
				 break;
			case UPLOAD_ALBUM:
				 intent = new Intent(context, ActivityAlbums.class);
			     context.startActivityForResult(intent, ActivityUpload.SELECT_ALBUM);
			     AnimUtil.getActivityTransition(context, true);
				break;
			case UPLOAD_COMMENT:
				dialogShowComment();
				break;
			case UPLOAD_TAGS:
				dialogShowTag();
				break;
			case UPLOAD_LOCATION:
				dialogShowLocation();
				break;
			case UPLOAD_PRIVACY:
				showDialogEditPrivacy();
				break;
			}
			
		}
		
	}
	 private void dialogShowComment() {

	        DialogManagerClass.showAddCommentDialog(context, ActivityUpload.comment, new onCommentChange() {

	            @Override
	            public void Changed(String text) {

	            	ActivityUpload.comment = text;

	            }
	        });

	    }
	 private void dialogShowTag() {

	        DialogManagerClass.showAddTagDialog(context, ActivityUpload.tag, new onTagChange() {

	            @Override
	            public void Changed(String text) {

	            	ActivityUpload.tag = text;

	            }
	        });
	    }
	 private void dialogShowLocation() {

	        DialogManagerClass.showShareLocationDialog(context);
	    }
	 private void showDialogEditPrivacy() {

	        DialogShare sha = new DialogShare(context, new OnShareChanged() {

	            @Override
	            public void Changed(int share) {

	              setPrivacy(context.getResources().getStringArray(R.array.picture_shared_with)[share]);
                  ActivityUpload.privacyIndex=share;
	            }
	        });
	        sha.show();

	    }
}
